<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //unshift(value);数组的头部添加一个或多个元素,并返回数组的新长度，修改原有数组
        Array.prototype.myUnshift = function () {
            //声明一个变量接收数组长度,新数组长度为sum = 原长度+新参长度
            var sum = this.length + arguments.length;
            // 给新数组从最后一个加进去
            for (var i = sum; i > 0; i--) {
                if (i > arguments.length) {
                    // 把原数组元素位置后移
                    this[i - 1] = this[i - 1 - arguments.length];
                }
                else {
                    this[i - 1] = arguments[i - 1];
                }
            }
            return sum;

        }
        var array1 = [1, 2, 3];
        var res1 = array1.myUnshift("a", "b", "c");
        console.log(array1);
    </script>
</body>

</html>